package cn.hubujyjs.lp.service.impl;

import cn.hubujyjs.lp.config.UserHolder;
import cn.hubujyjs.lp.utils.R;
import cn.hubujyjs.lp.vo.StudentTerminalVo;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hubujyjs.lp.domain.Terminal;
import cn.hubujyjs.lp.service.TerminalService;
import cn.hubujyjs.lp.mapper.TerminalMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author admin
* @description 针对表【terminal】的数据库操作Service实现
* @createDate 2023-05-16 23:19:18
*/
@Service
public class TerminalServiceImpl extends ServiceImpl<TerminalMapper, Terminal>
    implements TerminalService{

    @Override
    public R<List<StudentTerminalVo>> queryList() {
        Long id = UserHolder.getUser().getId();
        LambdaQueryWrapper<Terminal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Terminal::getUserId,id);
        List<Terminal> list = this.list(wrapper);
        if (list==null||list.size()==0){
            return R.ok();
        }
        List<StudentTerminalVo> objects = list.stream().map(i -> {
            StudentTerminalVo studentTerminalVo = new StudentTerminalVo();
            BeanUtil.copyProperties(i, studentTerminalVo);
            return studentTerminalVo;
        }).toList();
        return R.ok(objects);
    }
}




